In [1]:
%pip install -r requirements.txt
Requirement already satisfied: scipy in c:\users\stast\anaconda3\envs\venv\lib\site-packages (from -r requirements.txt (line 1)) (1.7.2)
Requirement already satisfied: wavfile in c:\users\stast\anaconda3\envs\venv\lib\site-packages (from -r requirements.txt (line 2)) (4.4.0)
Requirement already satisfied: rir-generator in c:\users\stast\anaconda3\envs\venv\lib\site-packages (from -r requirements.txt (line 3)) (0.2.0)
Requirement already satisfied: bitstring in c:\users\stast\anaconda3\envs\venv\lib\site-packages (from -r requirements.txt (line 4)) (4.0.1)
Requirement already satisfied: cffi>=1.1.0 in c:\users\stast\anaconda3\envs\venv\lib\site-packages (from rir-generator->-r requirements.txt (line 3)) (1.15.0)
Requirement already satisfied: numpy>=1.6 in c:\users\stast\anaconda3\envs\venv\lib\site-packages (from rir-generator->-r requirements.txt (line 3)) (1.21.2)
Requirement already satisfied: pycparser in c:\users\stast\anaconda3\envs\venv\lib\site-packages (from cffi>=1.1.0->rir-generator->-r requirements.txt (line 3)) (2.21)
Note: you may need to restart the kernel to use updated packages.
In [19]:
import numpy as np
import IPython
import matplotlib.pyplot as plt

from guitar import Guitar, CHORD_ARTICULATIONS, STRUM_UP, STRUM_DOWN

SAMPLE_RATE = 44100
In [17]:
import scipy.fft
def fft_plot(audio, sample_rate, max_display_freq=1000):
    n = len(audio)
    T = 1 / sample_rate
    yf = scipy.fft.fft(audio)
    xf = scipy.fft.fftfreq(n, T)
    plt.xlim((0, max_display_freq))
    plt.tight_layout()
    plt.plot(xf, 2 / n * np.abs(yf))
In [3]:
guitar_synth = Guitar(SAMPLE_RATE)
In [4]:
signal = guitar_synth.pinch_string(5, 5, 5)
In [5]:
IPython.display.Audio(signal, rate=SAMPLE_RATE, autoplay=False)
Out[5]:
Your browser does not support the audio element.
In [21]:
fft_plot(signal, SAMPLE_RATE, max_display_freq=5000)
In [6]:
signal2 = guitar_synth.pinch_string(4, 0, 5)
In [7]:
IPython.display.Audio(signal2, rate=SAMPLE_RATE, autoplay=False)
Out[7]:
Your browser does not support the audio element.
In [8]:
chord_signal = guitar_synth.pinch_chord(CHORD_ARTICULATIONS["C"], 3)
In [9]:
IPython.display.Audio(chord_signal, rate=SAMPLE_RATE, autoplay=False)
Out[9]:
Your browser does not support the audio element.
In [10]:
signal = guitar_synth.pinch_rythmic_pattern(CHORD_ARTICULATIONS["Am"], [0.5, 0.25, 0.25, 0.5, 0.5])
In [11]:
IPython.display.Audio(signal, rate=SAMPLE_RATE, autoplay=False)
Out[11]:
Your browser does not support the audio element.
In [12]:
signal = guitar_synth.strum_rythmic_pattern(["Am", "Am", "Am", "C", "C"], durations=[0.5, 0.25, 0.25, 0.5, 0.5], directions=[STRUM_DOWN, STRUM_DOWN, STRUM_UP, STRUM_DOWN, STRUM_UP])
In [13]:
IPython.display.Audio(signal, rate=SAMPLE_RATE, autoplay=False)
Out[13]:
Your browser does not support the audio element.
In [14]:
chords = [
    "Am", "Am", "Am", 
    "Dm", "Dm", "Dm", 
    "G", "G", "G", "G", 
    "C", "C", "C", "C",
    "Am", "Am", "Am", 
    "Dm", "Dm", "Dm", 
    "G", "G", "G", "G", 
    "C", "C", "C", "C",
    "Am", "Am", "Am", 
    "Dm", "Dm", "Dm", 
    "G", "G", "G", "G", 
    "C", "C", "C", "C",
    "Am", "Am", "Am", 
    "Dm", "Dm", "Dm", 
    "G", "G", "G", "G", 
    "E", "E", "E", "E",
    "E", "E", "E",
]
durations = [
    1/2, 1/4, 1/4, 
    1/2, 1/4, 1/4, 
    1/4, 1/4, 1/4, 1/4, 
    1/4, 1/4, 1/4, 1/4,
    1/2, 1/4, 1/4, 
    1/2, 1/4, 1/4, 
    1/4, 1/4, 1/4, 1/4, 
    1/4, 1/4, 1/4, 1/4,
    1/2, 1/4, 1/4, 
    1/2, 1/4, 1/4, 
    1/4, 1/4, 1/4, 1/4, 
    1/4, 1/4, 1/4, 1/4,
    1/2, 1/4, 1/4, 
    1/2, 1/4, 1/4, 
    1/4, 1/4, 1/4, 1/4, 
    1/4, 1/4, 1/4, 1/4,
    1/4, 1/4, 3/2
]
directions = [
    1, 1, 0, 
    1, 1, 0, 
    1, 0, 1, 0, 
    1, 0, 1, 0,
    1, 1, 0, 
    1, 1, 0, 
    1, 0, 1, 0, 
    1, 0, 1, 0,
    1, 1, 0, 
    1, 1, 0, 
    1, 0, 1, 0, 
    1, 0, 1, 0,
    1, 1, 0, 
    1, 1, 0, 
    1, 0, 1, 0, 
    1, 1, 1, 1,
    1, 1, 1
]
powers = [
    1, 0.8, 0.7, 
    1, 0.8, 0.7, 
    0.8, 0.8, 0.8, 0.8, 
    0.8, 0.8, 0.8, 0.8,
    1, 0.8, 0.7, 
    1, 0.8, 0.7, 
    0.8, 0.8, 0.8, 0.8, 
    0.8, 0.8, 0.8, 0.8,
    1, 0.8, 0.7, 
    1, 0.8, 0.7, 
    0.8, 0.8, 0.8, 0.8, 
    0.8, 0.8, 0.8, 0.8,
    1, 0.8, 0.7, 
    1, 0.8, 0.7, 
    0.8, 0.8, 0.8, 0.8, 
    1.2, 1.2, 1.2, 1.2,
    1.2, 1.2, 1.2
]
tempo = 1
In [15]:
song = guitar_synth.strum_rythmic_pattern(
    articulations=chords,
    durations=durations,
    tempo=tempo,
    directions=directions,
    powers=powers,
)
In [16]:
IPython.display.Audio(song, rate=SAMPLE_RATE, autoplay=True)
Out[16]:
Your browser does not support the audio element.